<%--
  Created by IntelliJ IDEA.
  User: CrazyTobis
  Date: 2020-05-11
  Time: 21:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="tcjDetail">
    <div class="" id="">
        <div class="row">
            <div class="col-2">
                <input class="form-control "readonly value="采购订单：${data.orderNo}">
            </div>
            <div class="col-2">
                <input class="form-control "readonly value="供应商：${data.supplierName}">
            </div>
            <div class="col-2">
                <input class="form-control "readonly value="单据状态：${data.documentsState}">
            </div>
            <div class="col-6">
                <input class="form-control "readonly value="采购备注：${data.remarks}">
            </div>
        </div>
    </div>

    <%--${tableColumn}--%>
    <%@ include file="cgddlayout/cgddDetail.jsp"%>

    <div class="alert alert-secondary h6" role="alert" data-tcj="all" style="color: #0A160A">
        <b style="font-weight: 700">合计：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            物品种类：${wpzl}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            物品总数：${wpzs}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            成本总价：${cbzj}
        </b>
    </div>

    <div>
        <div style="top: 0px;
        left: -5px;
        width: 159px;
        height: 30px;
        background: #e2f3ff;
        border-radius: 0 17px 17px 0;
        color: #2397f3;
        text-align: center;
        line-height: 30px;">
            经办信息
        </div>

        <div id="cgddInfoTable" style="padding-bottom: 50px">
            <%@ include file="cgddlayout/cgddTable.jsp"%>
        </div>
    </div>
</div>

<script>
    (function () {

        <%--let info =   ${info};--%>
        $('[data-xhq="cgdd-shenHe-baocun"]').on('click',function () {
            $(this).returnMianbao();
        });
        $('[data-xhq="cgdd-shenHe-tijiao"]').on('click',function () {

            // 将采购订单和审核备注和审核的结果发送给服务器
            let formSer = $('form[data-xhq-form="purchase-audit"]').serialize();
            let href = $('form[data-xhq-form="purchase-audit"]').attr('href');
            let action = $('form[data-xhq-form="purchase-audit"]').attr('action');
            let orderNo = "${orderNo}";

            let reqResult = "";
            if(formSer.indexOf("result=2") > -1){
                reqResult = "是否确认【同意】该订单的审核？";
            }else if(formSer.indexOf("result=3") > -1){
                reqResult = "是否确认【拒绝】该订单的审核？";
            }

            swal({
                title: reqResult,
                text: "【"+orderNo+"】",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#0CC27E',
                cancelButtonColor: '#FF586B',
                confirmButtonText: '确定',
                cancelButtonText: "取消"
            }).then(
                function (isConfirm) {
                    // 确认订单
                    if (isConfirm) {
                        let data = {
                            ordId : "${orderNo}",
                            reqType : "2"
                        };
                        for (let temp in data){
                            formSer+="&"+temp+"="+data[temp];
                        }

                        console.log(formSer);

                        $.post(href,formSer,function (res) {


                            if(res.code === "200"){
                                swal(
                                    '订单审核操作成功！',
                                    '',
                                    'success'
                                );
                                $(this).returnMianbao();
                                $('#refreshThisNav').trigger('click');
                            }else{
                                swal(
                                    '订单审核操作失败！',
                                    '',
                                    'success'
                                );
                                alert("【"+ orderNo + "】订单提交失败");
                            }
                        },'json');
                    }
                }).catch(swal.noop);



        });

        $('[data-xhq="cgdd-queRen-baocun"]').on('click',function () {
            $(this).returnMianbao();
        });
        $('[data-xhq="cgdd-queRen-tijiao"]').on('click',function () {
             let orderNo = "${orderNo}";
            swal({
                title: '是否确认采购该订单?',
                text: "【"+orderNo+"】",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#0CC27E',
                cancelButtonColor: '#FF586B',
                confirmButtonText: '确认',
                cancelButtonText: "取消"
            }).then(
                function (isConfirm) {
                    // 确认订单
                    if (isConfirm) {

                        let formSer = $('form[data-xhq-form="purchase-audit"]').serialize();
                        let href = $('form[data-xhq-form="purchase-audit"]').attr('href');

                        let data = {
                            ordId : "${orderNo}",
                            reqType : "3",
                            result : "4"
                        };
                        for (let temp in data){
                            formSer+="&"+temp+"="+data[temp];
                        }
                        console.log(formSer);

                        $.post(href,formSer,function (res) {
                            if(res.code === "200"){
                                $.post("addBill",JSON.stringify(res.data),function (r) {

                                    if(r > 0){
                                        swal(
                                            '订单确认采购操作成功！',
                                            '',
                                            'success'
                                        );

                                        $(this).returnMianbao();
                                        $('#refreshThisNav').trigger('click');
                                    }else{
                                        swal(
                                            '订单确认采购操作失败！',
                                            '',
                                            'success'
                                        );
                                    }
                                });
                            }else{
                                swal(
                                    '订单确认采购操作失败！',
                                    '',
                                    'success'
                                );
                            }
                        },'json');
                    }
                }).catch(swal.noop);
        });
    })();
</script>